home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2004 July & August
/
PCWorld_2004-07-08_cd.bin
/
Software
/
topware
/
sandra
/
san2004.SP1-9104-Win32-SSO.exe
/
{app}
/
examples
/
SQL Server Schema.sql
< prev
next >
Wrap
Text File
|
2003-12-16
|
4KB
|
155 lines
--
-- SQL Server 7.0/2000 Schema for Sandra Report
--
-- Database is assumed to have been created already.
-- No size settings included, please add as required.
--
-- Copyright 1995-2004, C. A. Silasi, SiSoftware.
-- All Rights Reserved.
--
--USE Sandra;
--
-- Kill all tables
--
IF exists(select * from sysobjects where id = object_id('Item') and OBJECTPROPERTY(id, 'IsTable') = 1)
DROP TABLE Item;
IF exists(select * from sysobjects where id = object_id('ItemGroup') and OBJECTPROPERTY(id, 'IsTable') = 1)
DROP TABLE ItemGroup;
IF exists(select * from sysobjects where id = object_id('Device') and OBJECTPROPERTY(id, 'IsTable') = 1)
DROP TABLE Device;
IF exists(select * from sysobjects where id = object_id('Class') and OBJECTPROPERTY(id, 'IsTable') = 1)
DROP TABLE Class;
IF exists(select * from sysobjects where id = object_id('Module') and OBJECTPROPERTY(id, 'IsTable') = 1)
DROP TABLE Module;
IF exists(select * from sysobjects where id = object_id('Report') and OBJECTPROPERTY(id, 'IsTable') = 1)
DROP TABLE Report;
IF exists(select * from sysobjects where id = object_id('IDCount') and OBJECTPROPERTY(id, 'IsTable') = 1)
DROP TABLE IDCount;
--
-- Create new tables
--
CREATE TABLE Report (
ID INT IDENTITY (1,1),
ProgramName VARCHAR(255),
ProgramVersion VARCHAR(255),
RegisteredUser VARCHAR(255),
RegisteredCompany VARCHAR(255),
LicenceStatus VARCHAR(255),
LicenceExtra VARCHAR(255),
UserID VARCHAR(255),
HostName VARCHAR(255),
SystemID VARCHAR(255),
WebUserID VARCHAR(255),
RunID VARCHAR(255),
RunDate DATETIME,
Completed BIT NOT NULL,
CONSTRAINT cnstRIID PRIMARY KEY(ID)
);
CREATE TABLE Module (
ID INT IDENTITY (1,1),
ReportID INT NOT NULL,
Name VARCHAR(255) NOT NULL,
TypeID INT NOT NULL,
HasClass BIT NOT NULL,
HasDevice BIT NOT NULL,
HelpID INT NOT NULL,
CONSTRAINT cnstMIID PRIMARY KEY(ID),
CONSTRAINT cnstMRID FOREIGN KEY(ReportID) REFERENCES Report(ID)
);
CREATE TABLE Class (
ID INT IDENTITY (1,1),
ModuleID INT NOT NULL,
Name VARCHAR(255) NOT NULL,
TypeID INT NOT NULL,
HelpID INT NOT NULL,
CONSTRAINT cnstCIID PRIMARY KEY(ID),
CONSTRAINT cnstCMID FOREIGN KEY(ModuleID) REFERENCES Module(ID)
);
CREATE TABLE Device (
ID INT IDENTITY (1,1),
ModuleID INT NOT NULL,
ClassID INT,
Name VARCHAR(255) NOT NULL,
TypeID INT NOT NULL,
HelpID INT NOT NULL,
CONSTRAINT cnstDIID PRIMARY KEY(ID),
CONSTRAINT cnstDMID FOREIGN KEY(ModuleID) REFERENCES Module(ID)
);
CREATE TABLE ItemGroup (
ID INT IDENTITY (1,1),
ModuleID INT NOT NULL,
ClassID INT,
DeviceID INT,
Name VARCHAR(255) NOT NULL,
TypeID INT NOT NULL,
HelpID INT NOT NULL,
CONSTRAINT cnstGIID PRIMARY KEY(ID),
CONSTRAINT cnstGMID FOREIGN KEY(ModuleID) REFERENCES Module(ID)
);
CREATE TABLE Item (
ID INT IDENTITY (1,1),
ModuleID INT NOT NULL,
GroupID INT,
Name VARCHAR(255) NOT NULL,
DataValue VARCHAR(255),
IconID INT NOT NULL,
TypeID INT NOT NULL,
HelpID INT NOT NULL,
CONSTRAINT cnstIIID PRIMARY KEY(ID),
CONSTRAINT cnstIMID FOREIGN KEY(ModuleID) REFERENCES Module(ID)
);
CREATE TABLE IDCount (
TableName VARCHAR(10) PRIMARY KEY,
CurrentID INT NOT NULL
);
--
-- Set-up keys/indexes
--
CREATE INDEX ndxUserID ON Report (UserID);
CREATE INDEX ndxSystemID ON Report (SystemID);
CREATE INDEX ndxWebUserID ON Report (WebUserID);
CREATE INDEX ndxModuleName ON Module (Name);
CREATE INDEX ndxItemName ON Item (Name);
--
-- Inserts
--
INSERT INTO IDCount (TableName, CurrentID) VALUES ('Item', 1);
INSERT INTO IDCount (TableName, CurrentID) VALUES ('ItemGroup', 1);
INSERT INTO IDCount (TableName, CurrentID) VALUES ('Device', 1);
INSERT INTO IDCount (TableName, CurrentID) VALUES ('Class', 1);
INSERT INTO IDCount (TableName, CurrentID) VALUES ('Module', 1);
INSERT INTO IDCount (TableName, CurrentID) VALUES ('Report', 1);